<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <script src="jquery.min.js"></script>
    <script src="markdown.js"></script>
    <link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
    <style>

        code {
            margin:0;
            padding:1em;
            background:#F9F9F9;
            border:1px dashed #2F6FAB;
            display:block;
            white-space:pre;
            font-family:"Courier New", Courier, monospace;
            color:#666;
            line-height:1.5;
            overflow:auto;
        }
    </style>
</head>
<body>
<?php
session_start();
if (isset($_GET['mdpsd'])) {
    if ($_GET['mdpsd'] != "xienaizhong") {
    } else {
        $_SESSION['loginmd'] = "1";
    }
    header("Location:/doc");
}
if(isset($_SESSION['loginmd'])) {
    if ($_SESSION['loginmd'] != "1") {
        exit("<form method='get'><input name='mdpsd'><input type='submit' value='提交'></form>");
    }
}else{
    exit("<form method='get'><input name='mdpsd'><input type='submit' value='提交'></form>");
}

?>


<textarea id="text-input" oninput="this.editor.update()"
          rows="6" cols="60" style="display: none;"><?php if(isset($_GET['f'])) include $_GET['f'] . ""; ?></textarea>
<div id="preview"></div>

<script>
    function Editor(input, preview) {
        this.update = function () {
            preview.innerHTML = markdown.toHTML(input.value);
        };
        input.editor = this;
        this.update();
    }
    var $ = function (id) {
        return document.getElementById(id);
    };
    new Editor($("text-input"), $("preview"));


</script>

<hr>






<?php

$dir = __DIR__;
$file = scandir($dir);
$index = 1;
foreach ($file as $x) {
    if (strpos($x, ".md") >= 1) {
        echo "<a href='/doc/show.php?f=" . $x . "'>" . $x . "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($index % 4 == 0) {
            echo "<br>";
        }
        $index = $index +1;
    }
}

?>

</body>
</html>